﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace SSABSZ.SuperEP.Core
{
    public static class SettingsHolder
    {
        public static string GetValue(string BasePath, string SubPath, string Name)
        {
            return (string) Registry.GetValue(BasePath + "\\" + SubPath, Name, string.Empty);
        }

        public static void SetValue(string BasePath, string SubPath, string Name, string value)
        {
            Registry.SetValue(BasePath + "\\" + SubPath, Name, value, RegistryValueKind.String);
        }

        public static string GetValue(string BasePath, string SubPath, string Name, string defaultval)
        {
            return GetValue(BasePath, SubPath, Name, defaultval, true);
        }

        public static string GetValue(string BasePath, string SubPath, string Name, string defaultval, bool saveIfNotThere)
        {
            var value = (string)Registry.GetValue(BasePath + "\\" + SubPath, Name, defaultval);
            if (value == null) value = defaultval;
            if (value == string.Empty) value = defaultval;
            if(saveIfNotThere)
                Registry.SetValue(BasePath + "\\" + SubPath, Name, value, RegistryValueKind.String);
            return value;
        }
    }
}
